$(document).ready(function() {
	selCompanys();//初始加载公司列表
	
	if(userId != ''){
		$("#title").html("修改用户");
		initUpdateUserInfo();
	}else{
		$("#title").html("新增用户");
	}
	
});

function initUpdateCompany(ccode){

	$.ajax({  
          type : "post",  
          url : "/finance/resources/selResources.do",  
          async : false,  
          success :function(str1){
			var data1 = eval('(' + str1 + ')');
			if(data1.success){
			var html = "";
			for(var i=0; i<data1.data.length; i++){
				html+=""+(i%5==0?"<br/>":"")+"<input type=\"checkbox\" name=\"resouceschecked\" value=\""+data1.data[i].id+"\"/>"+data1.data[i].ResourceCode+" ";
			}
			}else{
				jAlert("加载公司列表失败,请联系管理员!","提示");			
			}
			$("#showResource").html(html);
		   }
        });  
	
	jQuery.post("/finance/company/initUpdateCompany.do",
		{id:id},function(str){
			var data = eval('(' + str + ')');
			$("#companyId").val(data.id);
			$("#companyCode").val(data.companyCode);
			$("#companyName").val(data.companyName);
			var crs = data.crs;
			$(":checkbox[name='resouceschecked']").each(function (i,v){
				for(var a=0 ;a<crs.length;a++){
					if($(v).val() ==crs[a].resourceId ){
						$(v).attr("checked","checked");
					}
				}
			});
	      });
}

